#include<bits/stdc++.h>
#include<iostream>
#include <unordered_map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
struct  Team{
	string name;
	int points=0;
	int goal_diff=0;
	bool operator<(Team& other){
		if(points!=other.points){
			 return points > other.points;  // 积分高的排前面
		} return goal_diff > other.goal_diff; // 积分相同，净胜球多的排前面
	}
};
int main(){
	int T;
	cin>>T;
    for(int test_case=0;test_case<T;++test_case){
    	// 存储所有球队信息：key为队名，value为对应Team结构体
        unordered_map<string, Team> team_db;
        // 处理12场比赛
        for(int i = 0; i < 12; ++i){
        	string home_team, away_team, vs_str;
        	int home_score, away_score;
            // 输入并解析比赛信息
            cin >> home_team >> home_score >> vs_str >> away_score >> away_team;
            // 如果球队未初始化，则加入数据库
            if (team_db.find(home_team) == team_db.end()) {
                team_db[home_team] = {home_team, 0, 0};
            }
            if (team_db.find(away_team) == team_db.end()) {
                team_db[away_team] = {away_team, 0, 0};
            }
        	Team& home = team_db[home_team];
            Team& away = team_db[away_team];
            
            int goal_diff = home_score - away_score;
            if (goal_diff > 0) {
                // 主队赢：+3分，净胜球增加
                home.points += 3;
                home.goal_diff += goal_diff;
                away.goal_diff -= goal_diff;
            }
            else if (goal_diff < 0) {
                // 客队赢：+3分，净胜球增加
                away.points += 3;
                away.goal_diff += (-goal_diff);
                home.goal_diff += goal_diff;
            }
            else {
                // 平局：双方各加1分
                home.points += 1;
                away.points += 1;
            }
		}
		 // 将所有球队放入 vector 中以便排序
        vector<Team> teams;
        for (const auto& item : team_db) {
            teams.push_back(item.second);
        }
         // 排序
        sort(teams.begin(), teams.end());
        // 输出前两名
        cout << teams[0].name << " " << teams[1].name << endl;
	}
	return 0;
}